﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OracleClient;

public partial class Services_getCorrelationCoefficient_Disease : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.ContentType = "text/xml";
        Response.Charset = "utf-8";
        Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");

        string AgriParamList = "";
        string RsIndexList = "";
        string ImageID = "";
        string DistrictId = "";
        string SamplingDate = "";


        string resultXml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" + "\n";
        resultXml += "<RxyList>" + "\n";

        ImageID = Request.QueryString[0].ToString().Trim();
        AgriParamList = Request.QueryString[1].ToString().Trim();
        RsIndexList = Request.QueryString[2].ToString().Trim();

        //SamplingDate = ImageID.Remove(2);

        string queryString = "select DISTID,IMAGEDATE from RS.DISTRICT_IMAGE_SP_REF where IMAGEID = '" + ImageID + "'";
        OracleDataReader myReader = OracleDataBase.ExecuteReader(queryString);
        if (myReader.Read())
        {
            DistrictId = myReader[0].ToString();
            SamplingDate = Convert.ToDateTime(myReader[1]).ToShortDateString();
        }


        string[] AgriParamArray = AgriParamList.Split(',');
        string[] RsIndexArray = RsIndexList.Split(',');
        int AgriParamCount = AgriParamArray.Length;
        int RsIndexCount = RsIndexArray.Length;
        try
        {
            for (int i = 0; i < AgriParamCount; i++)
            {
                for (int j = 0; j < RsIndexCount; j++)
                {
                    AgriRSModel_Disease myModel;
                    if (AgriParamArray[i].StartsWith("UP_"))
                    {
                        AgriParamArray[i] = AgriParamArray[i].Substring(3);
                        myModel = new AgriRSModel_Disease(AgriParamArray[i], RsIndexArray[j], SamplingDate, DistrictId);
                    }
                    else//待仔细处理
                    {
                        myModel = new AgriRSModel_Disease(AgriParamArray[i], RsIndexArray[j], SamplingDate, DistrictId);
                    }


                    double R = myModel.calculateRelatedCoefficient(myModel.AgriParamDataset, myModel.RSIndexDataset);
                    resultXml += "<Rxy agri = '" + AgriParamArray[i] + "' rsindex = '" + RsIndexArray[j] + "' r = '" + R + "' />" + "\n";

                }
            }
            resultXml += "</RxyList>" + "\n";

            Response.Write(resultXml);
        }
        catch (Exception ex)
        {
            resultXml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" + "\n";
            resultXml += "<RxyList>" + "\n";
            resultXml += "</RxyList>" + "\n";
            Response.Write(resultXml);
            throw ex;
        }
    }
}
